package main

import (
	"crypto/sha512"
	"fmt"
	"go_final/mxshop_srvs/user_srv/model"

	"github.com/anaskhan96/go-password-encoder"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

func main() {
	dsn := "root:root@tcp(192.168.4.111:3306)/mxshop_user_srv?charset=utf8mb4&parseTime=True&loc=Local"

	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})

	if err != nil {
		fmt.Println("err", err)
	}

	options := &password.Options{SaltLen: 16, Iterations: 100, KeyLen: 32, HashFunction: sha512.New}
	salt, encodedPwd := password.Encode("admin123", options)
	passwd := fmt.Sprintf("$pbkdf2-sha512$%s$%s", salt, encodedPwd)

	for i := 0; i < 10; i++ {
		user := model.User{
			Mobile:   fmt.Sprintf("1897705755%d", i),
			Password: passwd,
			NickName: fmt.Sprintf("用户%d", i),
		}
		db.Create(&user)
	}
}
